package bbs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.whu.administrator.ws.R;

import java.util.List;

import bbs.model.Subject;

/**
 * Created by nimi on 2015/11/10.
 */
public class MainViewAdapter extends BaseAdapter{
    private static List<Subject> subjects;
    private Context mContext;
    public MainViewAdapter(Context context, List<Subject> subjects) {
        this.mContext=context;
        this.subjects= subjects;
    }
    //返回已获得数据源总数量
    public int getCount() {
        // TODO Auto-generated method stub
        if (subjects != null)
            return subjects.size();
        else
            return 0;
    }

    @Override
    //告诉适配器取得目前容器中的数据对象
    public Subject getItem(int position) {
        // TODO Auto-generated method stub
            return subjects==null?null:subjects.get(position);

    }
    @Override
    //告诉适配器取得目前容器中的数据ID
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    //取得当前欲显示的图像View
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
            LayoutInflater _LayoutInflater = LayoutInflater.from(mContext);
            convertView = _LayoutInflater.inflate(R.layout.bbs_board_item, null);
            if (convertView != null) {
                TextView _TextView1 = (TextView) convertView.findViewById(R.id.HomeItemTitle);
                _TextView1.setText(subjects.get(position).getTopic_Name());
            }

        return convertView;
    }


}
